package main

import (
	"fmt"
	"sync"
)

var num = 0

var wg sync.WaitGroup

// 互斥锁
var lock sync.Mutex

func main() {
	wg.Add(2)
	go add()
	go add()
	wg.Wait()
	fmt.Println(num)
}

func add() {
	defer wg.Done()
	for i := 1; i <= 50000; i++ {
		lock.Lock()
		num += 1
		lock.Unlock()
	}
}
